
import readline

commands = """
set
random
save
list
exit
wq
help
--edit
--read-only
show
hide
""".strip().split("\n")


class AutoComplite:
    def __init__(self):
        self.command_list = commands
        
        self._Complit()

    def _Complit(self):

        def Completer(text, state):
            options = [option for option in self.command_list if option.lower().startswith(text.lower())]
            if state < len(options):
                return options[state]
            else:
                return None
                
        readline.set_completer( Completer )
        readline.parse_and_bind('tab: complete')

    def ADD_VALUE(self, value: str):
        if value in self.command_list:
            return
            
        self.command_list.append( value )
        
        self._Complit()
